﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JqueryNet.FormControl.FormHtmlControl
{
    public class JHtmlTableCell : JHtmlControl
    {
        private System.Web.UI.HtmlControls.HtmlTableCell htmlTableCell;

        public JHtmlTableCell(System.Web.UI.HtmlControls.HtmlTableCell htmlTableCell)
            : base(htmlTableCell)
        {
            // TODO: Complete member initialization
            this.htmlTableCell = htmlTableCell;
        }

        public override void Attr(string key)
        {
            switch (key.ToLower())
            {
                case "align":
                    Value = htmlTableCell.Align;
                    return;
                case "bgcolor":
                    Value = htmlTableCell.BgColor;
                    return;
                case "bordercolor":
                    Value = htmlTableCell.BorderColor;
                    return;
                case "colspan":
                    Value = htmlTableCell.ColSpan;
                    return;
                case "height":
                    Value = htmlTableCell.Height;
                    return;
                case "nowrap":
                    Value = htmlTableCell.NoWrap;
                    return;
                case "valign":
                    Value = htmlTableCell.VAlign;
                    return;
                case "width":
                    Value = htmlTableCell.Width;
                    return;
                default:
                    base.Attr(key); return;
            }
        }

        public override void Html()
        {
            Value = htmlTableCell.InnerHtml;
        }

        public override void Html(Func<string> fun)
        {
            htmlTableCell.InnerHtml = fun();
        }

        public override void Html(string value)
        {
            htmlTableCell.InnerHtml = value;
        }

        public override void Text()
        {
            Value = htmlTableCell.InnerText;
        }

        public override void Text(Func<string> fun)
        {
            htmlTableCell.InnerText = fun();
        }

        public override void Text(string value)
        {
            htmlTableCell.InnerText = value;
        }


        public override void Attr(string key, string value)
        {
            int b;
            int.TryParse(value, out b);
            bool f;
            bool.TryParse(value, out f);
            switch (key.ToLower())
            {
                case "align":
                    htmlTableCell.Align = value;
                    return;
                case "bgcolor":
                    htmlTableCell.BgColor = value;
                    return;
                case "bordercolor":
                    htmlTableCell.BorderColor = value;
                    return;
                case "colspan":
                    htmlTableCell.ColSpan = b;
                    return;
                case "height":
                    htmlTableCell.Height = value;
                    return;
                case "nowrap":
                    htmlTableCell.NoWrap = f;
                    return;
                case "valign":
                    htmlTableCell.VAlign = value;
                    return;
                case "width":
                    htmlTableCell.Width = value;
                    return;
                default:
                    base.Attr(key, value); return;
            }
        }
    }
}
